<?php
header("Content-type: text/html; charset=utf-8");
	/**
	* 封装成一个地址类，输入地址和职位即可采集
	*/
	class Caiji{
		private $url; //定义接口地址
		private $data; //定义向接口请求的需要发送请求的数据
		function __construct($url,$data=null){
			$this->url = $url;
			$this->data = $data;
		}
		function url_caiji(){
			$ch = curl_init(); //初始化，也叫开始
			// print_r($ch);
			curl_setopt( $ch, CURLOPT_URL, $this->url ); //给$ch配置参数
			curl_setopt( $ch, CURLOPT_POST, 1 );
			curl_setopt( $ch, CURLOPT_HEADER, 0 );
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
			curl_setopt( $ch, CURLOPT_POSTFIELDS, $this->data );
			$return = curl_exec( $ch ); //执行
			curl_close( $ch ); //关闭请求

			$Object = json_decode ($return);  //将json转成PHP需要格式,下面的操作需要把对象打印出来看看结构
			// var_dump($Object);
			$Object_content = $Object->content; 
			// var_dump($Object_content);
			$Object_content_result = $Object_content->result;
			// var_dump($Object_content_result);
			// var_dump($Object_content_result[0]);
			// var_dump(count($Object_content_result));
			$company_result_id = array();
			//依次取出数据存进数组中
			for ($i=0; $i <count($Object_content_result) ; $i++) { 
				$company_result_id[$i]["positionId__url"] = "http://www.lagou.com/jobs/".$Object_content_result[$i]->positionId.".html";
			}
			return $company_result_id;	//最后将结果返回给外面调用对象用		
		}
		
	}



?> 